import pymysql

conn = pymysql.connect(host="localhost", port=3306, user="root", password="root", database="test", charset="utf8")
cursor = conn.cursor()

try:
    # %s 只是一个参数占位符，可以传入任意参数类型，可以防止sql注入
    sql = "insert into students (name, gender, height) values (%s, %s, %s)"
    cursor.execute(sql, ["ting", "女", 1.65])
    conn.commit()
except Exception as e:
    print(e)
    conn.rollback()


cursor.close()
conn.close()